'''
Created on 3 juil. 2010

@author: nathanael
'''

__all__ = ['Style']


from lxml import etree

class ColorZone(object):
    def __init__(self, color, node, fromto):
        self.color = color
        self.node = node
        self.fromto = fromto
        
    def __call__(self, e):
        if e == self.node:
            text = e.text
            del e.text
            jj = 00
            for i, j in self.fromto:
                ee = etree.Element('div')
                ee.text = text[jj:i - 1]
                e.append(ee)
                ee = etree.Element('div', attrib={'color':self.color})
                ee.text = text[i:j]
                e.append(e)
                jj = j + 1
            ee = etree.Element('div')
            ee.text = text[jj:]
            e.append(ee)
        return e

class Style(object):
    def __init__(self, *styles):
        self.styles = styles
    
    def __call__(self, e):
        for s in self.styles:
            e = s(e)
        return e

    def get_element(self):
        return etree.Element('style')
